package com.votereport.android;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

/*
 * This is the main application activity that sets everything up
 */
public class VoteReportMain extends Activity {
	
	 private static final int STOPSPLASH = 0;
     //time in milliseconds
     private static final long SPLASHTIME = 2000; 
     
     private ImageView splash; 
     
   //handler for splash screen
     private Handler splashHandler = new Handler() {
          /* (non-Javadoc)
           * @see android.os.Handler#handleMessage(android.os.Message)
           */
          @Override
          public void handleMessage(Message msg) {
               switch (msg.what) {
               case STOPSPLASH:
                    //remove SplashScreen from view
                   // splash.setVisibility(View.GONE);
                    
                    showLocationFinder();
                 
                    break;
               }
               super.handleMessage(msg);
          }
     };
     
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setTheme(android.R.style.Theme_Light);

        setContentView(R.layout.splash);
        
       splash = (ImageView) findViewById(R.id.splashscreen);
       Message msg = new Message();
       msg.what = STOPSPLASH;
       splashHandler.sendMessageDelayed(msg, SPLASHTIME);
             
           Toast.makeText(getBaseContext(), 
        		   R.string.splash_msg,
               Toast.LENGTH_LONG).show();
           
          getDeviceGUID();
    } 
    
	private void getDeviceGUID()
	{
		TelephonyManager mgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
		
		String deviceId = mgr.getDeviceId();
		
		Log.i("main","got device id: " + deviceId);
		
		Reporter.setDeviceGuid(deviceId);
	}
    
    private void showReportForm ()
    {
    	
    	Intent iReportForm = new Intent(this, ReportFormActivity.class);
        
        startActivity(iReportForm);
    }
    
    private void showLocationFinder ()
    {
    	
    	
    	Intent i = new Intent(this, LocationFinderActivity.class);
        
        startActivity(i);
    }
    
    
}